<?php 
  include_once '../../common/sql.php';
   $currentPage=$_POST['currentPage']; 
   $pageSize=$_POST['pageSize'];
   $category=$_POST['category'];
   $status=$_POST['status'];
   $offset=($currentPage-1)*$pageSize;
    
    $where= " where 1=1 ";
    if($category!="all"){
    	$where .=" and p.category_id='$category' ";
    };
    if($status!="all"){
    	$where .=" and p.status='$status'";
    };
   $conn=connect();
   $sql="select p.id,p.created,p.title,p.status,c.name,u.nickname
        from posts p 
        left join categories c on c.id= p.category_id
        left join users u on u.id= p.user_id
        $where 
        limit $offset,$pageSize";

     $bool= query($conn,$sql);
     
     $arr="select count(*) count from posts p $where";
     
     $count=query($conn,$arr)[0]['count'];
        
     $res=["code"=>0,"msg"=>'请求失败'];

    if($bool){
       $res['code']=1;
       $res['msg']='请求成功';
       $res['data']=$bool;
       $res['count']=$count;
    }

    echo json_encode($res);
 ?>